package com.teacher.hong.dao;

import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 分数数据访问类
 */
@Repository
public class ScoreDao {

    @Resource
    BaseDao baseDao;

    /**
     * 根据学生ID查询分数条数
     * @param studentId
     * @return
     */
    public int selectCountByStudentId(int studentId) throws SQLException {
        int count = 0;
        ResultSet resultSet = baseDao.query("select count(0) from score where student_id=" + studentId);
        if (resultSet.next()) {
            count = resultSet.getInt(1);
        }
        return count;
    }

    /**
     * 根据学生ID查询总分
     * @param studentId
     * @return
     */
    public int selectSumScoreByStudentId(int studentId) throws SQLException {
        int count = 0;
        ResultSet resultSet = baseDao.query("select sum(num) from score where student_id=" + studentId);
        if (resultSet.next()) {
            count = resultSet.getInt(1);
        }
        return count;
    }


}
